package com.cgycms.webdeploy.common;

import cn.hutool.json.JSONUtil;
import lombok.Data;

/**
 * @ClassName : Result
 * @Description : 返回对象
 * @Author : 王力超
 * @Date: 2020-11-04 16:40
 */
@Data
public class Result<T> {

    private Integer code;

    private String msg;

    private T data;


    public static String ok() {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("操作成功!");
        return JSONUtil.toJsonStr(result);
    }

    public static String ok(Object data) {
        Result result = new Result();
        result.setCode(200);
        result.setData(data);
        result.setMsg("操作成功!");
        return JSONUtil.toJsonStr(result);
    }

    public static String ok(String msg) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg(msg);
        return JSONUtil.toJsonStr(result);
    }

    public static String ok(Integer code ,String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return JSONUtil.toJsonStr(result);
    }

    public static String ok(Integer code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        return JSONUtil.toJsonStr(result);
    }

    public static String fail() {
        Result result = new Result();
        result.setCode(500);
        result.setMsg("操作成功!");
        return JSONUtil.toJsonStr(result);
    }

    public static String fail(Object data) {
        Result result = new Result();
        result.setCode(500);
        result.setData(data);
        result.setMsg("操作成功!");
        return JSONUtil.toJsonStr(result);
    }

    public static String fail(Integer code,String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return JSONUtil.toJsonStr(result);
    }

    public static String fail(String msg) {
        Result result = new Result();
        result.setCode(500);
        result.setMsg(msg);
        return JSONUtil.toJsonStr(result);
    }

    public static String fail(Integer code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        return JSONUtil.toJsonStr(result);
    }

    public static String fail(Object data,String msg) {
        Result result = new Result();
        result.setCode(500);
        result.setData(data);
        result.setMsg(msg);
        return JSONUtil.toJsonStr(result);
    }


}


